package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.PageInFoDomain;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.NursingRecord;
import com.ruoyi.system.interfaces.Add;
import com.ruoyi.system.interfaces.Audit;
import com.ruoyi.system.service.INursingRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理记录Controller
 *
 * @author jinyao
 */
@RestController
@RequestMapping("/nursing/record")
@RequiredArgsConstructor
public class NursingRecordController extends BaseController {


    private final INursingRecordService nursingRecordService;

    @PostMapping("/list")
    public AjaxResult list(NursingRecord nursingRecord) {
        PageInFoDomain<NursingRecord> page = nursingRecordService.selectNursingRecordList(nursingRecord);
        return AjaxResult.success(page);
    }

    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        NursingRecord nursingRecord = nursingRecordService.selectNursingRecordById(id);
        return AjaxResult.success(nursingRecord);
    }


    @Log(title = "护理记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(NursingRecord nursingRecord) {
        List<NursingRecord> list = nursingRecordService.selectNursingRecordList(nursingRecord).getRows();
        ExcelUtil<NursingRecord> util = new ExcelUtil<>(NursingRecord.class);
        return util.exportExcel(list, "护理记录数据");
    }


    @Log(title = "护理记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated({Add.class}) NursingRecord nursingRecord) {
        return toAjax(nursingRecordService.insertNursingRecord(nursingRecord));
    }


    @Log(title = "护理记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NursingRecord nursingRecord) {
        return toAjax(nursingRecordService.updateNursingRecord(nursingRecord));
    }

    @Log(title = "审核记录", businessType = BusinessType.AUDIT)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody @Validated({Audit.class}) NursingRecord nursingRecord){
        return AjaxResult.success(nursingRecordService.audit(nursingRecord));
    }


    @Log(title = "护理记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String ids) {
        return toAjax(nursingRecordService.deleteNursingRecordByIds(ids));
    }

    @Log(title = "取消记录", businessType = BusinessType.UPDATE)
    @GetMapping("/stop/{id}")
    public AjaxResult stop(@PathVariable Long id) {
        return toAjax(nursingRecordService.stop(id));
    }
}
